UI components
UI components are things you can put in a scene to make them interactive they come in three types:
- Buttons
- Input Fields
- Chat display
If you want to uses theses component make sure to use a shared pointer.
Buttons
Buttons have a really simple logic, first you build them using their constructor, then you call their update member to know if they are pressed or not.
They have 4 parameters:
- position
sf::Vector2f pos
- Police Size
sf::Vector2f size
- Text content
std::string text
- Font
sf::Font &font
The update function of a button return true
if the button is released and false
otherwise. It also set the internal state of the button to have an effect on hover.
Inputs Fields
Inputs Fields have 3 parameters that influence the style:
- Position
- Police Size
- Font
And 2 more parameters for the input in itself
- placeholder text, displayed when input is empty
std::string _placeHolder
- accepted characters, characters that can be used in the input field (all alphabet letters and digit by default)
std::string _accept
Input fields also have a gestion of internal state to know when they are hovered or focused on.
The way you get the information differ from the button as the update member only return false.
Instead there is a setter and getter pair for the input:
void setInput(std::string input)
std::string getInput()
Chat display
Chat display is not a component a user can interact with, it's used as a text display.
If you know about the Minecraft chat, then you know what this one look likes.
The only customisable parameters are the Font
, the max
number of message displayed and the color
of the text.
The text always have a size of 17
.
To add a message to the chat simply use the add Message funtion:
void addMessage(std::string msg, sf::Color color)
By default the color of the text is white.